﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Resources;

namespace DVK.SP2007
{
    /// <summary>
    /// AspNetResourceManager offers resources from Application Global Resources directory.
    /// <remarks>
    /// AspNetResourceManager is needed as an abstraction in some places where IDvkResourceManager is used.
    /// Such requirement comes from the code being used both by timer jobs and asp.net.
    /// On webpages code, i normally use strongly typed Resources directly to avoid specifying the key.
    /// </remarks>
    /// </summary>
    public class AspNetResourceManager : IDvkResourceManager
    {
        private ResourceManager _baseResourceManager;

        /// <summary>
        /// Initializes a new instance of the <see cref="AspNetResourceManager"/> class.
        /// Default is initialized with Dvk.resx ResourceManager.
        /// </summary>
        public AspNetResourceManager()
            : this(Resources.Dvk.ResourceManager)
        { }
        /// <summary>
        /// Initializes a new instance of the <see cref="AspNetResourceManager"/> class.
        /// </summary>
        /// <param name="baseResourceManager">The base resource manager.</param>
        public AspNetResourceManager(ResourceManager baseResourceManager)
        {
            _baseResourceManager = baseResourceManager;
        }

        #region IDvkResourceManager Members

        /// <summary>
        /// Gets the resource value based on key.
        /// </summary>
        /// <param name="key">The resource key.</param>
        /// <returns>resource value</returns>
        public string GetString(string key)
        {
            return _baseResourceManager.GetString(key);
        }

        /// <summary>
        /// Gets the resource based on enum element.
        /// </summary>
        /// <typeparam name="T">type of enum</typeparam>
        /// <param name="enumValue">The enum element value.</param>
        /// <returns>localized string</returns>
        public string GetResourceBasedOnEnumElement<T>(T enumValue)
        {
            return _baseResourceManager.GetResourceBasedOnEnumElement<T>(enumValue);
        }

        /// <summary>
        /// Gets the resource based on enum element.
        /// The data inputed will be used in string.Format to fill in the data gaps in the localized string.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumValue">The enum value.</param>
        /// <param name="data">The data.</param>
        /// <returns>localized string</returns>
        public string GetResourceBasedOnEnumElement<T>(T enumValue, params object[] data)
        {
            return _baseResourceManager.GetResourceBasedOnEnumElement<T>(enumValue, data);
        }

        #endregion
    }
}
